package com.innovation.sys.common.job;

import java.io.IOException;
import java.util.Date;
import java.util.List;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import com.innovation.sys.common.constant.SourceParam;
import com.innovation.sys.common.utils.ExportExcelUtils;
import com.innovation.sys.common.utils.FileUtils;
import com.innovation.sys.common.utils.LangUtils;
import com.innovation.sys.dao.SSysLogMapper;
import com.innovation.sys.pojo.SSysLog;

@Component
public class AutoTask {

	private static Logger logger = LoggerFactory.getLogger(AutoTask.class);

	@Resource
	private SSysLogMapper sSysLogMapper;

	private final String path = SourceParam.EXPORT_PATH + "\\" + "日志操作记录" + LangUtils.formatDate(new Date(), "yyyyMMdd")
			+ ".xlsx";

	// 定时生成日志文件
	public void uploadLogToServer() throws IOException {
		List<SSysLog> findAllExplicitly = sSysLogMapper.findAllExplicitly();
		ifExistFolder(SourceParam.EXPORT_PATH);
		logger.info("文件路径为:{}" + path);
		ExportExcelUtils.writeExcel(findAllExplicitly, path);
	}

	// 判断路径是否存在，不存在则创建
	private void ifExistFolder(String path) {
		FileUtils.isExistFolder(path);
	}

}
